package com.hxzy.util;

import org.apache.commons.beanutils.Converter;

import java.sql.Timestamp;

/**
 * @author nick
 * @description
 * @date create in 2020/9/11
 */
public class DateTimeConverter implements Converter {

    /**
     * 将从数据库中取出的value值转换为type对应的类型
     * @param type 类中属性参数的类型
     * @param value 数据库中取出的value值
     * @return
     */
    @Override
    public Object convert(Class type, Object value) {
        return toLocalDateTime(type, value);
    }

    //转向日期类型
    //value为form提交日期字符串
    public static Object toLocalDateTime(Class type, Object value) {
        System.out.println("class:" + type.getName() + ",========== value type:" + value.getClass().getName() + ",value:" + value);
        if (type.equals(java.time.LocalDateTime.class)) {
            if (value instanceof Timestamp) {
                Timestamp timestamp = (Timestamp) value;
                return timestamp.toLocalDateTime();
            }
        }
        return value;
    }
}
